/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package physical_spaces.business;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import physical_spaces.DAO.PhysicalSpaceDAO;

/**
 *
 * @author chucho
 */
public class GlobalVariablesBusiness {

    private ResultSet resultSet;    

    public GlobalVariablesBusiness() {
    }
    
    
    public GlobalVariablesBusiness(ResultSet resultSet) {
        this.resultSet = resultSet;
    }

    public List<GlobalVariable> getGlobalVariables() {
        List<GlobalVariable> globalVariables = new ArrayList<>();
        try {
            while (resultSet.next()) {
                GlobalVariable globalVariable = new GlobalVariable(resultSet.getString(1), resultSet.getString(2));
                globalVariables.add(globalVariable);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return globalVariables;
    }
    
    public boolean setValue( String name, String value){
        PhysicalSpaceDAO psdao = new PhysicalSpaceDAO();
        try {
            psdao.set(name, value);
            return true;
            
        } catch ( SQLException ex) {
            System.out.println("ERROR!!! " + ex);
            return false;
        }
    }
}
